package org.jsets.fastboot.routingds.impl;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * 
 * 多数据源切换上下文
 * 
 * @author wj596
 *
 */
public class RoutingDataSourceContext {

	private static final ThreadLocal<Deque<String>> CTX = new ThreadLocal<Deque<String>>() {
		@Override
		protected Deque<String> initialValue() {
			return new ArrayDeque<String>();
		}
	};

	public static void push(String dataSourceName) {
		CTX.get().push(dataSourceName);
	}

	public static void poll() {
		Deque<String> deque = CTX.get();
		deque.poll();
		if (deque.isEmpty()) {
			CTX.remove();
		}
	}

	public static String peek() {
		return CTX.get().peek();
	}

	public static void clear() {
		CTX.remove();
	}

}